---
title: "Public Officials' Online Sharing of Low-factual Content: Institutional and Ideological Checks"
output: html_document
date: "2025-08-11"
---


```{r setup, include=FALSE}
#install.packages('knitr')
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE)

if (!require(pacman))
  install.packages("pacman")
library(pacman)

pacman::p_load(
tidyverse,
janitor,
kableExtra,
patchwork,
usdata,
here,
usmap,
rio, 
Amelia,
readxl,
fuzzyjoin,
lme4,
interplot,
dotwhisker,
broom.mixed,
pscl,
modelsummary,
performance,
lmtest,
ggeffects,
#marginaleffects,
sjPlot,
stargazer,
brms,
cmdstanr, 
glmmTMB,
ggbeeswarm,
sandwich,
rvest)
remotes::install_github("stan-dev/cmdstanr")

options(scipen = 999)

set.seed(425)


```


```{r data-input-Table A.0}

load(here::here("data","analysis_data.rda"))
load(here::here("data","shor_mccarty_ide.rda")) #Shor_McCarty ideology data can be downloaded from Individual State Legislator Shor-McCarty Ideology Data at dataverse. 

dfs_des <- analysis_data %>%
  mutate(female = ifelse(gender == "F", 1,0))  %>%
                          filter(n_url > 0) %>%
                          dplyr::select(n_lf, n_lowfact_total_weighted, n_url, 
                                                                         n_nosocial, shor_ideo, mrp_lr, mrp_ideology_se,
                                                                         demshare_pres, squire_prof2015, bowen_md1 ,
                                                                         Termlimit ,legis_salary,avestaffnum ,
                                                                         senate,polarization,female,state_mrp_ideology,pop_num,
                                                                         per_bachhigher) %>%
  rename( `Number of low-factual URLs` = n_lf, 
          `Number of weighted low-factual URLs` = n_lowfact_total_weighted, 
          `Number of posts with URLs` = n_url, 
          `Number of posts with URLs \n excluding social media links` = n_nosocial, 
           `Ideology` = shor_ideo, 
          `Public Ideology` =  mrp_lr, 
          `Public Ideology (SE)` = mrp_ideology_se, 
          `DemPreshare` = demshare_pres, 
          `Professionalism score` = squire_prof2015, 
          `Professionalism component-md1s` = bowen_md1, 
          `Term limit` = Termlimit,
           `Salary` = legis_salary,
          `Number of Staff` = avestaffnum, 
          `Senate` = senate,
           `Polarization` = polarization,
          `Gender(Female)` = female,
          `State ideology` = state_mrp_ideology,
          `Population` = pop_num,
           `Bachelor’s or Higher (%)` = per_bachhigher)



stargazer(as.data.frame(dfs_des),  type = "latex")


```

```{r stats_ideo_Figure A.2,fig.width=15, fig.height= 9, fig.align='center'}

dem_med_ide <- analysis_data %>%
   filter( n_url > 0) %>%
 group_by(party3) %>%
  summarise(median = median(shor_ideo, na.rm = T)) %>%
  filter(party3 == "Democratic") %>%
  pull(median)

rep_med_ide <-analysis_data %>%
   filter( n_url > 0) %>%
 group_by(party3) %>%
  summarise(median = median(shor_ideo, na.rm = T)) %>%
  filter(party3 == "Republican") %>%
  pull(median)

max(analysis_data$shor_ideo,na.rm = T) #3.857
min(analysis_data$shor_ideo,na.rm = T) #-3.277

his_ideo <- ggplot(analysis_data  %>% filter( n_url > 0), aes(shor_ideo)) + geom_histogram() + 
  geom_vline(xintercept = dem_med_ide, linetype = 2, size = 2) +
  geom_text(aes(x= -2.4, label= paste0("Democrats'", "\n median ideology = ", round(dem_med_ide,3)), y= 500),  angle=0, vjust = 1.2, size = 9)  +
  geom_vline(xintercept = rep_med_ide, linetype = 2, size = 2)  +
  geom_text(aes(x= 2.3, label= paste0("Republicans'", "\n median ideology = ", round(rep_med_ide,3)), y= 500),  angle=0, vjust = 1.2, size = 9)  +
   xlab("Ideology") + ylab("")  +
  scale_x_continuous(breaks = c(-3.3, -3, -2, -1, 0, 1, 2, 3, 3.9),
                     labels=c("-3.3" ="Far \nLeft", "-3" = "-3", "-2"="-2", "-1"="-1", "0" = "0", "1"="1", "2" = "2", "3" = "3", "3.9" = "Far \nRight")) + 
   theme_bw(base_size = 30) +
  theme(
        axis.text.y  = element_text(face = "bold"),
       axis.text.x  = element_text(face = "bold"), 
       axis.title = element_text(face = "bold")
 )
   

while (!is.null(dev.list()))  dev.off()

ggsave("FigureA2.png", his_ideo, path = here::here("output"), 
       width = 15, height = 7)

dem_med_allide <- shor_mccarty_ide %>%
 group_by(Party) %>%
  summarise(median = median(shor_ideo, na.rm = T)) %>%
  filter(Party == "Dem") %>%
  pull(median)

rep_med_allide <- shor_mccarty_ide %>%
 group_by(Party) %>%
  summarise(median = median(shor_ideo, na.rm = T)) %>%
  filter(Party == "Rep") %>%
  pull(median)

max(shor_mccarty_ide$shor_ideo,na.rm = T) #3.857
min(shor_mccarty_ide$shor_ideo,na.rm = T) #-3.277

shor_mccarty_ide_dis <- ggplot(shor_mccarty_ide, aes(shor_ideo)) + geom_histogram() + 
  geom_vline(xintercept = dem_med_allide, linetype = 2, size = 2) +
  geom_text(aes(x= -2.55, label= paste0("Democrats'","\n median ideology = ", round(dem_med_allide,3)), y= 900),  angle=0, vjust = 1.6, size = 8.5)  +
  geom_vline(xintercept = rep_med_allide, linetype = 2, size = 2)  +
  geom_text(aes(x= 2.3, label= paste0("Republicans'","\n median ideology = ", round(rep_med_allide,3)), y= 900),  angle=0, vjust = 1.6, size = 8.5)  +
   xlab("Ideology") + ylab("")  +
  scale_x_continuous(breaks = c(-3.3, -3, -2, -1, 0, 1, 2, 3, 3.5, 4),
                     labels=c("-3.3"= "Far \nLeft", "-3" = "-3", "-2"="-2", "-1"="-1", "0" = "0", "1"="1", "2" = "2", "3" = "3", "3.5" = "3.5", "4" = "Far \nRight")) + 
  theme_bw(base_size = 25) +
  theme(
        axis.text.y  = element_text(face = "bold"),
       axis.text.x  = element_text(face = "bold"), 
       axis.title = element_text(face = "bold")
 )
print(shor_mccarty_ide_dis)
while (!is.null(dev.list()))  dev.off()
ggsave("FigureA2b.png", shor_mccarty_ide_dis, path = here::here("output"), 
       width = 15, height = 7)

```


```{r stats_ideo_Figure A.3,fig.width=15, fig.height= 9, fig.align='center'}
overdispersion <- ggplot(analysis_data  %>% filter( n_url > 0), aes(n_lf)) + geom_histogram() +
  scale_y_continuous(trans = scales::pseudo_log_trans(base=10),
                     breaks=c(0,2, 5, 10, 30,100, 300,500,1000,2000, 3000, 4000)) +
  scale_x_continuous(trans = scales::pseudo_log_trans(base=10), 
                     breaks=c(0,1,10, 20,50,100,200, 300, 400))  +
  xlab("Count of Shared Low-fact URLs") + 
  ylab("Count of Legislators")  + 
   theme_bw(base_size = 30) +
  theme(
        axis.text.y  = element_text(face = "bold"),
       axis.text.x  = element_text(face = "bold"), 
       axis.title = element_text(face = "bold")
 )
print(overdispersion)
while (!is.null(dev.list()))  dev.off()
ggsave("FigureA3.png", overdispersion, path = here::here("output"), 
       width = 15, height = 9)

```

#Main Model

```{r nourl_prof_mainmodels}

#standardize data
analysis_data[,c("squire_prof2015", "bowen_md1","shor_ideo", "polarization", "mrp_lr",  "demshare_pres", "state_mrp_ideology")] <- scale(analysis_data[,c("squire_prof2015", "bowen_md1","shor_ideo",  "polarization", "mrp_lr", "demshare_pres","state_mrp_ideology")])



########low fact
ide_lf <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo + mrp_lr + gender  + senate  + polarization + (1|state_chamber),data=analysis_data %>% filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(ide_lf ) 

idemrp_lf <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   + gender  + senate  + polarization + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_lf ) 


idemrp_squpro_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   + squire_prof2015 + Termlimit  +  gender  + senate  + polarization + (1|state_chamber),data=analysis_data%>%  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_squpro_all) 


idemrp_squpro_all_robust <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   + squire_prof2015 + Termlimit  +  gender  + senate  + polarization + log(pop_num) + state_mrp_ideology + per_bachhigher +  (1|state_chamber),data=analysis_data%>%  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_squpro_all_robust ) 


###clustered standard error

ide_lf_cluster <- MASS::glm.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo + mrp_lr  +  gender  + senate  + polarization,data=analysis_data %>%  filter( n_url > 0))

summary(ide_lf_cluster)
idemrp_lf_cluster <- MASS::glm.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr  +  gender  + senate  + polarization,data=analysis_data %>%  filter( n_url > 0))

summary(idemrp_lf_cluster)

squire_idemrp_lf_cluster <- MASS::glm.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr  + squire_prof2015 +  Termlimit  +  gender  + senate  + polarization,data=analysis_data %>%  filter( n_url > 0))

summary(squire_idemrp_lf_cluster)

squire_idemrp_lf_all_cluster <- MASS::glm.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr  + squire_prof2015 +  Termlimit  +  gender  + senate  + polarization + log(pop_num) + state_mrp_ideology + per_bachhigher,data=analysis_data %>%  filter( n_url > 0))

summary(squire_idemrp_lf_all_cluster)

cluster_chamber <- analysis_data %>%  filter( n_url > 0)



```

```{r Figure3, fig.width=19, fig.height= 12, fig.align='center'}

#ide_squpro_lf idemrp_squpro_lf idemrp_squpro_all,idemrp_squpro_all_robust

m1_url <- broom.mixed::tidy(ide_lf, effects = "fixed",conf.int=TRUE) %>%
  dplyr::mutate(model = "Ideology Model") %>%
  filter(term != "(Intercept)")
 
m2_url <- broom.mixed::tidy(idemrp_lf, effects = "fixed",conf.int=TRUE) %>%
  dplyr::mutate(model = "Directional Model") %>%
  filter(term != "(Intercept)") 

m3_url <- broom.mixed::tidy(idemrp_squpro_all, effects = "fixed",conf.int=TRUE) %>%
  dplyr::mutate(model = "Professionalism Model") %>%
  filter(term != "(Intercept)")  

m4_url <- broom.mixed::tidy(idemrp_squpro_all_robust, effects = "fixed",conf.int=TRUE) %>%
  dplyr::mutate(model = "Professionalism Robustness Model") %>%
  filter(term != "(Intercept)")  

urlmodels1_3 <- rbind( m4_url,m3_url, m2_url,m1_url) %>%
  dplyr::mutate(model = factor(model,
                 levels = c(
                "Ideology Model", 
                "Directional Model",
                "Professionalism Model",
                "Professionalism Robustness Model")
        ))  %>%
    relabel_predictors(
     c( `log10(1 + n_url)` = "Posts of URLs(in log)",
        `log10(1 + n_nosocial)` = "Posts \nof NS-URLs(in log)",
                `genderM` = "Male",
        senate = "Senate",
               `shor_ideo:mrp_lr` = "Ideology * \nDistrict Public Ideology", 
             `shor_ideo:demshare_pres` = "Ideology * \nPublic Ideology\npresidential vote shares",
                mrp_lr = "District Public Ideology",
                demshare_pres = "Public Ideology\n(presidential vote shares)",
                squire_prof2015 = "Professionalism",
           #    bowen_md1 = "Professionalism",
               polarization = "Polarization",
               Termlimit = "Term limit",
        
               `log(pop_num)` = "Population(in log)",
               state_mrp_ideology = "State Public Ideology",
              per_bachhigher = "Bachelor’s or Higher (%)",
           `log(per_bachhigher)` = "Bachelor’s or Higher (%)",
              shor_ideo = "Ideology") ) 


url_f3_grey <- dwplot(urlmodels1_3,
       vline = geom_vline(
           xintercept = 0,
           colour = "grey60",
           linetype = 2,
           size = 1.5
       ), 
       dot_args=list(size= 3),
      whisker_args = list(size= 1.5),
  vars_order = c("Ideology","District Public Ideology", "Ideology * \nDistrict Public Ideology", "Professionalism","Public Ideology\n(presidential vote shares)", "Ideology * \nPublic Ideology\npresidential vote shares", "Salary", "Staff number","Term limit", "Session length", "Legislative Expenditure","Senate", "Polarization","Male","Population(in log)", "State Public Ideology","Bachelor’s or Higher (%)","Posts of URLs(in log)", "Posts of NS-URLs(in log)"),
       model_order = c( "Ideology Model", 
                "Directional Model",
                "Professionalism Model",
                "Professionalism Robustness Model"
                )
       )  +
    theme_bw(base_size = 30) + 
  labs(
    title = "Outcome Variable:",
    subtitle = "The Count of Low-fact Information Shares by Individual Legislators"
  ) +
 
 #  ggtitle("Outcome Variable: The Count of Low-fact Information Shares by Individual Legislators") + #Negative Binomial Regression of Low-fact \nInformation Distribution (n = 3,285)
    theme(
        plot.title = element_text(face = "bold", size = 34),
        legend.position = "right",
      #  legend.direction="horizontal",
        legend.justification = c(0, 0),
        legend.background = element_blank(),
        legend.text =  element_text(face = "bold",size = 28),
        legend.title.align = .5,
       legend.key.size = unit(1, "cm"),
        legend.title = element_blank(),
        plot.margin = margin(0, 0, 0, 0, "pt"),
        panel.border = element_rect(), 
        axis.text.y  = element_text(face = "bold",size = 28),
       axis.text.x  = element_text(face = "bold",size = 28)
 ) +
   scale_colour_manual(
        name = "Models",
        breaks = c("Ideology Model", 
                "Directional Model",
                "Professionalism Model",
                "Professionalism Robustness Model"
               ),
        values=c("Ideology Model" = "#bdbdbd",              # moderate grey
                  "Directional Model" = "#8c8c8c",           # medium grey
                  "Professionalism Model" = "#5c5c5c",       # darker grey
                   "Professionalism Robustness Model" = "#2c2c2c"  # very dark grey
                #"Prevote:Ideology Model"= "#c7e9b4",
                #"Prevote:Directional Model" = "#7fcdbb", 
              #  "Prevote:Directional Model with More Controls" = "#225ea8"
               ),   #https://colorbrewer2.org/
        labels = c("Ideology Model", 
                "Directional Model",
                "Professionalism Model",
                "Professionalism \nRobustness Model"
               ) )+ 
    scale_shape_discrete(
        name = "Models",
         breaks = c("Ideology Model", 
                "Directional Model",
                "Professionalism Model",
                "Professionalism Robustness Model"
               ),
        labels = c("Ideology Model", 
                "Directional Model",
                "Professionalism Model",
                "Professionalism \nRobustness Model"
               )
    ) +
    guides(
        shape = guide_legend("Models"), 
        colour = guide_legend("Models")
    ) 

url_f3_grey

ggsave("Figure3.png", url_f3_grey , path = here::here("output"), 
       width = 19, height = 12)

```

```{r interaction_plot_Figure4, fig.width=17, fig.height= 10}

interaction <- ggpredict(idemrp_squpro_all, terms = c( "shor_ideo","mrp_lr[-1, 1]")) 
quantile(analysis_data$shor_ideo,na.rm = T) #[quart2][meansd]
min(analysis_data$shor_ideo,na.rm = T)
max(analysis_data$shor_ideo,na.rm = T)
quantile(analysis_data$mrp_lr,na.rm = T) #[quart2][meansd]

###effect of individual ideology conditional on sd changes of public ideology
df_d <- data.frame(x1 = analysis_data$mrp_lr[which(analysis_data$party3=="Democratic")], x2 = analysis_data$mrp_lr[which(analysis_data$party3=="Democratic")], y1 = 0, y2 = .00001)

df_r <- data.frame(x1 = analysis_data$mrp_lr[which(analysis_data$party3=="Republican")], x2 = analysis_data$mrp_lr[which(analysis_data$party3=="Republican")], y1 = 100, y2 = 200)

pred_plot <- plot(interaction,colors = "bw") +  geom_line(size = 2) +
  labs( 
    x = "Lawmakers' ideology",
    y = "The count of low-factual URLs",
    title = "Predicted mean count of low-factual URLs",
    linetype = "Public ideology"
  )  + 
   scale_y_log10(breaks = c(0,0.001,0.1, 1, 5, 15, 50, 100), labels = c("0","0.001", "0.1","1", "5", "15", "50","100")) + 
 # scale_y_continuous(transform = "pseudo_log",breaks = c(0.001, 1, 5, 10, 25, 50, 100)) + 
  geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = df_d,inherit.aes=F,colour=rgb(0,0,0,maxColorValue=255,alpha=25)) +
  geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = df_r,inherit.aes=F,colour=rgb(0,0,0,maxColorValue=255,alpha=25)) +
  theme(legend.position = "bottom") +
  scale_linetype_manual(values = 2:3, labels = c("-1 SD", " +1 SD")) +
  scale_x_continuous(labels = c("Most \nLiberal\nin Analysis Data\n(-2.96)", "-2","-1", "0", "1","2", "3","Most \nConservative\nin Analysis Data\n(3.63)"), breaks = c(-2.96, -2,-1, 0, 1, 2, 3,3.63)) +
   theme(
        plot.title = element_text(face = "bold", size = 38),
      legend.position = "bottom",
       legend.background = element_blank(),
        legend.text =  element_text(face = "bold",size = 30),
        legend.title.align = .5,
        legend.title = element_text(face = "bold",size = 30),
      legend.key.size = unit(4.5, "lines"),
        plot.margin = margin(0, 0, 0, 0, "pt"),
      axis.title.y  = element_text(face = "bold",size = 34),
      axis.title.x  = element_text(face = "bold",size = 34),
        axis.text.y  = element_text(face = "bold",size = 24),
       axis.text.x  = element_text(face = "bold",size = 24),
  panel.background = element_rect(fill = "white", color = NA),
  plot.background = element_rect(fill = "white", color = NA)
 )

pred_plot
 
ggsave("Figure4.png", pred_plot,path = here::here("output"),width=17, height= 10 ) 

```

## Application in real world

```{r lf_state_party_extreme_Table1}
analysis_data %>%
  distinct(state_mrp_ideology, state) %>%
  arrange(-state_mrp_ideology) %>% 
      filter(row_number() == 1 | row_number() == n())

analysis_data %>%
  filter(n_url  > 0 ) %>%
  filter(state == "Massachusetts") %>%
  group_by(party3) %>%
  dplyr::summarise( 
            n_lf_per = sum(n_lf)/n())

analysis_data %>%
  filter(n_url  > 0 ) %>%
  filter(state == "Wyoming")  %>%
  group_by(party3) %>%
  dplyr::summarise( 
            n_lf_per =  sum(n_lf)/n())

```



```{r mainres_sum_Table A.2_Table A.2a}

##URL using professionalism index. ide_squpro_lf idemrp_squpro_lf idemrp_squpro_all ,idemrp_squpro_all_robust

##URL using professionalism index with different ideology and clustered se. vote_squpro_all vote_squpro_all_robust squire_idemrp_lf_cluster squire_idemrp_lf_all_cluster 

##URL usding alternative professionalism index. vote_squpro_all vote_squpro_all_robust, idemrp_bowpro_all idemrp_bowpro_all_robust vote_bowpro_all vote_bowpro_all_robust bowen_idemrp_lf_cluster bowen_idemrp_lf_all_cluster

#NS using different measures for public ideology: ns_ide_lf ns_idemrp_lf  ns_idemrp_lf_all ns_vote_ide_lf ns_vote_idemrp_lf ns_vote_idemrp_lf_all

#NS using different measures for professionalism: ns_bowen_ide_lf ns_bowen_idemrp_lf  ns_bowen_idemrp_lf_all ns_bowen_vote_ide_lf ns_bowen_vote_idemrp_lf ns_bowen_vote_idemrp_lf_all


mlng_main <- list(
   "Ideo"= ide_lf, #ide_squpro_lf,
   "Directional"= idemrp_lf, #idemrp_squpro_lf,
    "Professionalism"= idemrp_squpro_all,
   "ProfessionalismR"= idemrp_squpro_all_robust
  ) 

reorder_map_table2 <- c( "shor_ideo" = "Ideology",
                         "mrp_lr" = "Public Ideology",
                          "demshare_pres" = "Public Ideology\n(presidential vote shares)",
             "shor_ideo:mrp_lr" = "Ideology * Public Ideology", 
             "shor_ideo:demshare_pres" = "Ideology * \nPublic Ideology\npresidential vote shares",
                 "squire_prof2015" = "Professionalism",
           "bowen_md1" = "Professionalism",
            "Termlimit" = "Term limit",
            "genderM" = "Male",
        "senate" = "Senate",
         "polarization" = "Polarization",
         "log(pop_num)" = "Population(in log)",
               "state_mrp_ideology" = "State Ideology",
              "per_bachhigher" = "Bachelor and Higher (%)",
          "log(per_bachhigher)" = "Bachelor and higher (%)",
         "log10(1 + n_url)" = "Posts (in log)",
        "log10(1 + n_nosocial)" = "Posts \nof NS-URLs(in log)",
         "(Intercept)" = "Intercept",
        "SD (Intercept state_chamber)" = "SD (state_chamber)")
               
modelsummary(mlng_main,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
             title = "Table A.2: Negative Binomial Regression Results for low-factual URLs",
  statistic = NULL,
  
  coef_map = reorder_map_table2,
  output = "latex")



mlng_cluster <- list(
  "Ideo"= ide_lf, 
   "Directional"= idemrp_lf, 
    "Professionalism"= idemrp_squpro_all,
   "ProfessionalismR"= idemrp_squpro_all_robust,
   "Ideo_chamber"= ide_lf, 
   "Directional_chamber"= idemrp_lf, 
    "Professionalism_chamber"= idemrp_squpro_all,
   "ProfessionalismR_chamber"= idemrp_squpro_all_robust
  ) 


vcov_list <- list(
   "Ideo"= vcovCL(ide_lf_cluster, cluster_chamber$state),
   "Directional"= vcovCL(idemrp_lf_cluster, cluster_chamber$state),
 "Professionalism"  = vcovCL(squire_idemrp_lf_cluster, cluster_chamber$state),    
  "ProfessionalismR" = vcovCL(squire_idemrp_lf_all_cluster, cluster_chamber$state),  
   "Ideo_chamber"= vcovCL(ide_lf_cluster, cluster_chamber$state_chamber),
   "Directional_chamber"= vcovCL(idemrp_lf_cluster, cluster_chamber$state_chamber),
   "Professionalism_chamber"  = vcovCL(squire_idemrp_lf_cluster, cluster_chamber$state_chamber),    # default
  "ProfessionalismR_chamber" = vcovCL(squire_idemrp_lf_all_cluster, cluster_chamber$state_chamber)  # or another custom vcov if available
)

modelsummary(mlng_cluster, vcov = vcov_list,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
  statistic = NULL,
  title = "Table A.2a: Negative Binomial Regression with Clustered Standard Errors",
   coef_map = reorder_map_table2,
  output = "latex")
```



#Robustness check

```{r models4_tableA3}
####prof_vote as indicator of district-ideology
vote_squpro_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*demshare_pres   + squire_prof2015 + Termlimit  +  gender  + senate  + polarization + (1|state_chamber),data=analysis_data%>%  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(vote_squpro_all) 

idemrp_bowpro_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   +  bowen_md1 + Termlimit  +  gender  + senate  + polarization +  (1|state_chamber),data=analysis_data%>%  filter( n_url > 0) ,control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_bowpro_all ) 

vote_bowpro_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*demshare_pres   +  bowen_md1 + Termlimit  +  gender  + senate  + polarization +  (1|state_chamber),data=analysis_data%>%  filter( n_url > 0) ,control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(vote_bowpro_all ) 

ns_squire_idemrp_lf_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_nosocial)  + shor_ideo*mrp_lr + squire_prof2015  + as.factor(Termlimit) + polarization +  gender + senate +  (1|state_chamber),data=analysis_data%>%  filter( n_nosocial > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(ns_squire_idemrp_lf_all)

idemrp_lf_all_w <- glmmTMB(n_lowfact_total_weighted ~ log10(1 + n_url_w)  +  shor_ideo*mrp_lr   + squire_prof2015 + Termlimit  +  gender   + senate  + polarization   + (1|state_chamber),
                                data=analysis_data %>% 
                                  filter( n_url > 0) %>% 
                                  mutate(n_url_w = n_url - n_lf + n_lowfact_total_weighted),
                    family = nbinom2())
summary(idemrp_lf_all_w ) 

```


```{r leadership-TableA3}

load(here::here("data","analysis_leadership.rda"))

squire_idemrp_lf_all_leader <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo* mrp_lr  + squire_prof2015 + Termlimit  + gender + polarization + senate +  (1|state_chamber),data= analysis_leadership,control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(squire_idemrp_lf_all_leader) 


mlng_robust <- list(
  "VoteProf"= vote_squpro_all,
  "Professionalism_dim" = idemrp_bowpro_all,
  "VoteProfessionalism_dim" = vote_bowpro_all,
  "Exclude_SocialMedia" = ns_squire_idemrp_lf_all,
  "Weighted" = idemrp_lf_all_w,
  "Leadership_outsample" = squire_idemrp_lf_all_leader
  ) 

reorder_map_table3 <- c( "shor_ideo" = "Ideology",
                         "mrp_lr" = "Public Ideology",
                          "demshare_pres" = "DemPre_share",
             "shor_ideo:mrp_lr" = "Ideology * Public Ideology", 
             "shor_ideo:demshare_pres" = "Ideology * DemPre_share",
             "log(legis_salary + 1)" = "Salary (in log)",
             "log(avestaffnum + 1)" = "Staff (in log) ",
             "scale(legis_salary)" = "Salary (standardized)",
             "scale(avestaffnum)" = "Staff (Standardized)",
          #  "squire_prof2015" = "Professionalism",
          # "bowen_md1" = "Professionalism_dim1",
            "Termlimit" = "Term limit",
            "genderM" = "Male",
        "senate" = "Senate",
         "polarization" = "Polarization",
         "log(pop_num)" = "Population(in log)",
               "state_mrp_ideology" = "State Ideology",
              "per_bachhigher" = "Bachelor and Higher (%)",
          "log(per_bachhigher)" = "Bachelor and higher (%)",
         "log10(1 + n_url)" = "Posts (in log)",
        "log10(1 + n_nosocial)" = "Posts (in log)",
        # "(Intercept)" = "Intercept", 
        "SD (Intercept state_chamber)" = "SD (state_chamber)")
 

modelsummary(mlng_robust,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
  statistic = NULL,
  title = "Table A.3: Results from A Series of Robustness Checks",
   coef_map = reorder_map_table3,
  output = "latex")


```


```{r models4_TableA4}


idemrp_lf_all_comp <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   + log(legis_salary + 1)  + log(avestaffnum +1)  + Termlimit  +  gender  + senate  + polarization + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0) ,control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_lf_all_comp ) 


vote_idemrp_lf_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*demshare_pres   + log(legis_salary+1) +  log(avestaffnum +1)  + Termlimit + gender + polarization +   senate + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0) %>% 
                                  mutate(state_dis = paste(state_chamber, district_num, sep="_")),
                                  control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(vote_idemrp_lf_all ) 



idemrp_lf_all_comp_sd <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   + scale(legis_salary)  + scale(avestaffnum) +  Termlimit  +  gender  + senate  + polarization + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0) ,control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_lf_all_comp_sd ) 


vote_idemrp_lf_all_sd <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*demshare_pres   + scale(legis_salary) +  scale(avestaffnum)  + Termlimit + gender + polarization +   senate + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0) %>% 
                                  mutate(state_dis = paste(state_chamber, district_num, sep="_")),
                                  control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(vote_idemrp_lf_all_sd) 
```


```{r prof-component-TableA4}

mlng_comprobust <- list(
  "Professionalism" = idemrp_lf_all_comp,
   "VoteProfessionalism" = vote_idemrp_lf_all,
  "Professionalism" = idemrp_lf_all_comp_sd,
  "VoteProfessionalism" =  vote_idemrp_lf_all_sd
  ) 
 
modelsummary(mlng_comprobust,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
             title = "Table A.4: Results from Components of Legislative Professionalism, Using Different Transformation",
  statistic = NULL,
  coef_map = reorder_map_table3,
  output = "latex")

```

```{r outofsample-TableA.5}

idemrp_lf_all_outsample <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   + squire_prof2015 + Termlimit + gender + senate + polarization +    (1|state_chamber), data= analysis_data %>% 
                                  filter( n_url > 0 ) %>%
                                    filter(state != "Arizona"),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5)), nAGQ = 0)

summary(idemrp_lf_all_outsample ) 

idemrp_lf_all_outsamplewr <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   +  squire_prof2015  + Termlimit + gender + senate  + polarization  + (1|state_chamber),data= analysis_data %>% 
                                  filter( n_url > 0 ) %>%
                                    filter(official_id != "rogerswendy1"),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5)), nAGQ = 0)

summary(idemrp_lf_all_outsamplewr ) 

idemrp_lf_all_outsample2 <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   +  squire_prof2015  + Termlimit + gender + senate  + polarization +  (1|state_chamber),data= analysis_data %>% 
                                  filter( n_url > 0 ) %>%
                                    filter(state != "Pennsylvania"),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5)), nAGQ = 0)
summary(idemrp_lf_all_outsample2 ) 

idemrp_lf_all_outsampledm <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   +  squire_prof2015  + Termlimit + gender + senate  + polarization +  (1|state_chamber),data= analysis_data %>% 
                                  filter( n_url > 0 ) %>%
                                    filter(official_id != "mastrianodoug1"),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5)), nAGQ = 0)

summary(idemrp_lf_all_outsampledm ) 


idemrp_lf_all_outsample3 <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   +  squire_prof2015  + Termlimit + gender + senate  + polarization +   (1|state_chamber),data= analysis_data %>% 
                                  filter( n_url > 0 ) %>%
                                    filter(!(state %in% c( "Pennsylvania","Arizona"))),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5)), nAGQ = 0)
summary(idemrp_lf_all_outsample3 ) 

idemrp_lf_all_outsamplewrdm <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  +  shor_ideo*mrp_lr   +  squire_prof2015  + Termlimit + gender + senate  + polarization +    (1|state_chamber),data= analysis_data %>% 
                                  filter( n_url > 0 ) %>%
                                    filter(!(official_id  %in% c( "rogerswendy1","mastrianodoug1"))),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5)), nAGQ = 0)

summary(idemrp_lf_all_outsamplewrdm ) 

outsample <- list(
          "az_outsample" = idemrp_lf_all_outsample,
          "pa_outsample" = idemrp_lf_all_outsample2,
          "azpa_outsample" = idemrp_lf_all_outsample3,
          "wr_outsample" = idemrp_lf_all_outsamplewr,
          "dm_outsample" = idemrp_lf_all_outsampledm,
          "wrdm_outsample" = idemrp_lf_all_outsamplewrdm) 


modelsummary(outsample,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
  statistic = NULL,
  coef_map = reorder_map_table2,
  title = "Table A.5: Multilevel Negative Binomial Regression Results for low-factual URLs, excluding outliers",
  output = "latex")

```


```{r url_lf_zinbmodels}

ide_lf_zinb <- zeroinfl(n_lf ~ log10(1 + n_url) + shor_ideo + mrp_lr +  gender + senate + polarization |1,data=analysis_data %>% filter(n_url > 0), dist = "negbin")
summary(ide_lf_zinb)



ide_lf_zinb_zero <- zeroinfl(n_lf ~ log10(1 + n_url) + shor_ideo + mrp_lr +  gender + senate + polarization|log10(1 + n_url),data=analysis_data %>% filter(n_url > 0), dist = "negbin")
summary(ide_lf_zinb_zero)

idemrp_lf_zinb <- zeroinfl(n_lf ~ log10(1 + n_url) + shor_ideo*mrp_lr +  gender + senate + polarization |1,data=analysis_data %>% filter(n_url > 0), dist = "negbin")
summary(idemrp_lf_zinb)

idemrp_lf_zinb_zero <- zeroinfl(n_lf ~ log10(1 + n_url) + shor_ideo*mrp_lr +  gender + senate + polarization|log10(1 + n_url),data=analysis_data%>% filter(n_url > 0), dist = "negbin")
summary(idemrp_lf_zinb_zero)

pro_lf_zinb <- zeroinfl(n_lf ~ log10(1 + n_url)   + shor_ideo*mrp_lr  + squire_prof2015 + as.factor(Termlimit) + as.factor(Termlimit) + gender + senate + polarization  |1,data=analysis_data%>% filter(n_url > 0), dist = "negbin")
summary(pro_lf_zinb)

pro_lf_zinb_zero <- zeroinfl(n_lf ~ log10(1 + n_url)   + shor_ideo*mrp_lr  + squire_prof2015 + as.factor(Termlimit) + gender + senate + polarization  |log10(1 + n_url),data=analysis_data%>% filter(n_url > 0), dist = "negbin")

summary(pro_lf_zinb_zero)

```


```{r zinb_sum_TableA.6}
ZINB_Ideo_NZ <- list(
          "ZINB-Ide"= ide_lf_zinb,
          "ZINB-IdeMrp"= idemrp_lf_zinb,
          "ZINB-Prof"= pro_lf_zinb,
          "ZINB-Ide-Zero"= ide_lf_zinb_zero,
          "ZINB-IdeMrp-Zero"= idemrp_lf_zinb_zero,
          "ZINB-Prof-Zero"= pro_lf_zinb_zero) 


reorder_map_table6 <- c( "count_shor_ideo" = "Ideology",
                         "count_mrp_lr" = "Public Ideology",
                          "count_demshare_pres" = "Public Ideology",
             "count_shor_ideo:mrp_lr" = "Ideology * Public Ideology", 
             "count_shor_ideo:demshare_pres" = "Ideology * \nPublic Ideology\npresidential vote shares",
                 "count_squire_prof2015" = "Professionalism",
            "count_as.factor(Termlimit)1" = "Term limit",
            "count_genderM" = "Male",
        "count_senate" = "Senate",
         "count_polarization" = "Polarization",
         "count_log10(1 + n_url)" = "Count-Post(in log)",
         "count_(Intercept)" = "Count-Intercept",
             
         "zero_log10(1 + n_url)" = "Zero-Posts (in log)",
        "zero_(Intercept)" = "Zero-Intercept")
               

modelsummary(ZINB_Ideo_NZ,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
  statistic = NULL,
 title = "Table A.6: Probability of low-factual URLs Disseminated by State Lawmakers from
ZINB",
 coef_map = reorder_map_table6,
  output = "latex")
rbind(logLik=sapply(ZINB_Ideo_NZ,function(x) round(logLik(x),digits=0)), Df=sapply(ZINB_Ideo_NZ,function(x) attr(logLik(x),"df")))




```


```{r uncertainty-robust-TableA.7}
#running bayesian analysis takes time
moutcome <- brms::brm(bf(n_lf ~ 
                            log10(1 + n_url) +
                           me(mrp_ideology, mrp_ideology_se)*shor_ideo +
                           squire_prof2015 + Termlimit +  gender + senate + polarization +
                           (1 | state_chamber)),  
            data = analysis_data %>%  
              mutate(mrp_ideology = mrp_lr*(1)) %>%  
              filter(n_url > 0) %>%
              dplyr::select(n_lf, n_url,mrp_ideology, mrp_ideology_se,shor_ideo,squire_prof2015,Termlimit,state_chamber,gender, senate, polarization),
            backend = "cmdstanr",
            family= negbinomial(link = "log", link_shape = "identity"), 
            warmup = 1000, 
            iter = 2000, 
            chains = 4, 
            cores = 4,
            seed = 313)

summary(moutcome)

fit_summary <- summary(moutcome)
fixed_effects <- data.frame(
  Parameter = rownames(fit_summary$fixed),
  Estimate = fit_summary$fixed[, "Estimate"],
  StdError = fit_summary$fixed[, "Est.Error"],
  `2.5%` = fit_summary$fixed[, "l-95% CI"],
  `97.5%` = fit_summary$fixed[, "u-95% CI"],
  Rhat = fit_summary$fixed[, "Rhat"],
  Bulk_ESS = fit_summary$fixed[, "Bulk_ESS"],
  Tail_ESS = fit_summary$fixed[, "Tail_ESS"]
)

if (!is.null(fit_summary$random)) {
  random_effects <- data.frame(
    Parameter = "state_chamber",
    Estimate = fit_summary$random$state_chamber$Estimate,
    StdError = fit_summary$random$state_chamber$Est.Error,
  `2.5%` = fit_summary$random$state_chamber$`l-95% CI`,
  `97.5%` = fit_summary$random$state_chamber$`u-95% CI`,
  Rhat = fit_summary$random$state_chamber$Rhat,
  Bulk_ESS = fit_summary$random$state_chamber$Bulk_ESS,
  Tail_ESS = fit_summary$random$state_chamber$Tail_ESS
  )
}

if (!is.null(fit_summary$spec_pars)) {
  family_params <- data.frame(data.frame(
    Parameter = "shape",
    Estimate = fit_summary$spec_pars$Estimate,
    StdError = fit_summary$spec_pars$Est.Error,
    `2.5%` = fit_summary$spec_pars$`l-95% CI`,
    `97.5%` = fit_summary$spec_pars$`u-95% CI`,
    Rhat = fit_summary$spec_par$Rhat,
  Bulk_ESS = fit_summary$spec_pars$Bulk_ESS,
  Tail_ESS = fit_summary$spec_pars$Tail_ESS
  ))
}


save(moutcome, file = here::here("data", "moutcome.rda"))
load(here::here("data", "moutcome.rda"))

# Create a table using kableExtra
all_effects <- list(fixed_effects, random_effects,family_params) %>%
  purrr::compact() %>%
  dplyr::bind_rows()

save(all_effects, file = here::here("data","bayesian_all_effects.rda"))
load(here::here("data", "bayesian_all_effects.rda"))

# Create a table using kableExtra
table_latex <- all_effects %>%
   slice(c(3,9,10,4,5,6,7,8,2,11,12)) %>%
  mutate(Parameter = case_when(Parameter == "log101Pn_url" ~ "Posts (in log)", 
                               Parameter == "shor_ideo" ~ "Ideology",
         Parameter == "memrp_ideologymrp_ideology_se" ~ "Public Ideology", 
         Parameter == "memrp_ideologymrp_ideology_se:shor_ideo" ~ "Ideology * Public Ideology",
          Parameter == "squire_prof2015" ~ "Professionalism",
         Parameter == "Termlimit" ~ "Term limits", 
         Parameter == "genderM" ~ "Male",
         Parameter == "senate" ~ "Senate",
         Parameter == "polarization" ~ "Polarization",
          Parameter == "state_chamber" ~ "SD(Intercept)",
         .default = Parameter)) %>%
  kable("latex", booktabs = TRUE, digits = 2) %>%
  kable_styling(latex_options = c("scale_down"))

# Print LaTeX code
cat(table_latex)

```


```{r bays_Figure_A.5}
mareff <- conditional_effects(moutcome, "shor_ideo:mrp_ideology")
analysis_data <- analysis_data %>%  
              mutate(mrp_ideology = mrp_lr*(1))
sd(analysis_data$shor_ideo, na.rm = T)
mean(analysis_data$mrp_ideology, na.rm = T)

brm_plot <- plot(conditional_effects(moutcome, effects = "shor_ideo:mrp_ideology", 
                         int_conditions = list(mrp_ideology = c(-0.23, 0.21) ),
                         re_formula = NA), 
     points = F, rug = TRUE, robust = F,plot = FALSE)[[1]] + 
  labs( 
    x = "Lawmakers' ideology",
    y = "The count of low-fact URLs",
    title = "Predicted mean count of Low-fact URLs" ,
      color = "Public ideology",
     fill  = "Public ideology" 
  )  + 
  scale_y_log10() +
  theme(legend.position = "bottom") + 
  scale_color_grey(name = "Public ideology", labels = c("0.21" = "+ 1SD", "-0.23" = "- 1SD")) +
  scale_fill_grey(labels = c("0.21" = "+ 1SD", "-0.23" = "- 1SD")) 

ggsave("FigureA5.png", brm_plot, path = here::here("output"), 
       width = 10, height = 6) 

```

```{r polarization-sum-Table A.8}

ide_pol_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*polarization + mrp_lr + as.factor(Termlimit) + squire_prof2015  + gender +   senate  +   (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(ide_pol_all ) 

idemrp_pol_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*mrp_lr*polarization + as.factor(Termlimit) + squire_prof2015   + gender +   senate   + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_pol_all ) 

ide_term_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*as.factor(Termlimit) + mrp_lr+  polarization + squire_prof2015   + gender +   senate  +  (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(ide_term_all ) 

idemrp_term_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*mrp_lr*as.factor(Termlimit) + polarization + squire_prof2015   + gender +   senate   + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_term_all ) 

idemrp_termpol_all <- lme4::glmer.nb(n_lf ~ log10(1 + n_url)  + shor_ideo*as.factor(Termlimit)*polarization + mrp_lr + squire_prof2015   + gender +   senate  + (1|state_chamber),data=analysis_data %>% 
                                  filter( n_url > 0),control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)), nAGQ = 0)
summary(idemrp_termpol_all ) 



## the interaction effect does not depend on term limit (appeal to peers, not care about public), or polarization (if appeal to peers, then public's effect should be limited). 
Pol_Ideo <- list(
          "Polarization" = ide_pol_all,
          "Polarization-IdeMrp" = idemrp_pol_all,
          "Term" = ide_term_all,
          "Term-IdeMrp" = idemrp_term_all) 


reorder_map_table8 <- c( "shor_ideo" = "Ideology",
                         "mrp_lr" = "Public Ideology",
                          "demshare_pres" = "Public Ideology\n(presidential vote shares)",
                "polarization" = "Polarization",
             "as.factor(Termlimit)1" = "Term limit",
             
              "shor_ideo:mrp_lr" = "Ideology * Public Ideology", 
             "shor_ideo:demshare_pres" = "Ideology * \nPublic Ideology\npresidential vote shares",
            "shor_ideo:polarization" = "Ideology × Polarization",
            "mrp_lr:polarization" = "Public ideology × Polarization",
            "shor_ideo:mrp_lr:polarization" = "Ideology ×Public ideology × Polarization",
            "shor_ideo:as.factor(Termlimit)1" ="Ideology × Term Limits",
            "mrp_lr:as.factor(Termlimit)1" = "Public ideology × Term Limits",
            "shor_ideo:mrp_lr:as.factor(Termlimit)1" ="Ideology × Public ideology × Term Limits",
              "squire_prof2015" = "Professionalism",
           "bowen_md1" = "Professionalism",
            "genderM" = "Male",
        "senate" = "Senate",
         "log(pop_num)" = "Population(in log)",
               "state_mrp_ideology" = "State Ideology",
              "per_bachhigher" = "Bachelor and Higher (%)",
          "log(per_bachhigher)" = "Bachelor and higher (%)",
         "log10(1 + n_url)" = "Posts (in log)",
        "log10(1 + n_nosocial)" = "Posts \nof NS-URLs(in log)",
         "(Intercept)" = "Intercept",
        "SD (Intercept state_chamber)" = "SD (state_chamber)")


modelsummary(Pol_Ideo,
              fmt = NULL,
             estimate  = c(
                "{round(estimate,2)} ({round(std.error,2)}){stars}"),
  statistic = NULL,
   coef_map = reorder_map_table8,
  title = "Table A.8: Multilevel Negative Binomial Regression Results for low-factual URLs,
with polarization, term limits",
  output = "latex")

```




